/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for cmsPartnerTypeDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class cmsPartnerTypeDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsPartnerTypeDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsPartnerTypeDO objcmsPartnerTypeDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPartnerType_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@PartnerType", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPartnerTypeDO.PartnerType;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Description", SqlDbType.NText);
            Sqlparam.Value = objcmsPartnerTypeDO.Description;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Detail", SqlDbType.NText);
            Sqlparam.Value = objcmsPartnerTypeDO.Detail;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsPartnerTypeDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = objcmsPartnerTypeDO.OrderId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ParentID", SqlDbType.Int);
            Sqlparam.Value = objcmsPartnerTypeDO.ParentID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Sale", SqlDbType.Int);
            Sqlparam.Value = objcmsPartnerTypeDO.Sale;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SystemStatusId", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPartnerTypeDO.SystemStatusId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsPartnerTypeDO objcmsPartnerTypeDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPartnerType_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@PartnerTypeId", SqlDbType.Int);
            Sqlparam.Value = objcmsPartnerTypeDO.PartnerTypeId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PartnerType", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPartnerTypeDO.PartnerType;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Description", SqlDbType.NText);
            Sqlparam.Value = objcmsPartnerTypeDO.Description;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Detail", SqlDbType.NText);
            Sqlparam.Value = objcmsPartnerTypeDO.Detail;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsPartnerTypeDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = objcmsPartnerTypeDO.OrderId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ParentID", SqlDbType.Int);
            Sqlparam.Value = objcmsPartnerTypeDO.ParentID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Sale", SqlDbType.Int);
            Sqlparam.Value = objcmsPartnerTypeDO.Sale;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SystemStatusId", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPartnerTypeDO.SystemStatusId;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsPartnerTypeDO objcmsPartnerTypeDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPartnerType_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@PartnerTypeId", SqlDbType.Int);
            Sqlparam.Value = objcmsPartnerTypeDO.PartnerTypeId;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPartnerType_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsPartnerTypeDO Select(cmsPartnerTypeDO objcmsPartnerTypeDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPartnerType_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@PartnerTypeId", SqlDbType.Int);
            Sqlparam.Value = objcmsPartnerTypeDO.PartnerTypeId;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["PartnerTypeId"]))
                    objcmsPartnerTypeDO.PartnerTypeId = Convert.ToInt32(dr["PartnerTypeId"]);
                if (!Convert.IsDBNull(dr["PartnerType"]))
                    objcmsPartnerTypeDO.PartnerType = Convert.ToString(dr["PartnerType"]);
                if (!Convert.IsDBNull(dr["Description"]))
                    objcmsPartnerTypeDO.Description = Convert.ToString(dr["Description"]);
                if (!Convert.IsDBNull(dr["Detail"]))
                    objcmsPartnerTypeDO.Detail = Convert.ToString(dr["Detail"]);
                if (!Convert.IsDBNull(dr["CreatedDate"]))
                    objcmsPartnerTypeDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                if (!Convert.IsDBNull(dr["OrderId"]))
                    objcmsPartnerTypeDO.OrderId = Convert.ToInt32(dr["OrderId"]);
                if (!Convert.IsDBNull(dr["ParentID"]))
                    objcmsPartnerTypeDO.ParentID = Convert.ToInt32(dr["ParentID"]);
                if (!Convert.IsDBNull(dr["Sale"]))
                    objcmsPartnerTypeDO.Sale = Convert.ToInt32(dr["Sale"]);
                if (!Convert.IsDBNull(dr["SystemStatusId"]))
                    objcmsPartnerTypeDO.SystemStatusId = Convert.ToString(dr["SystemStatusId"]);

            }
            return objcmsPartnerTypeDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPartnerType_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsPartnerTypeDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsPartnerTypeDO objcmsPartnerTypeDO = new cmsPartnerTypeDO();
                    if (!Convert.IsDBNull(dr["PartnerTypeId"]))
                        objcmsPartnerTypeDO.PartnerTypeId = Convert.ToInt32(dr["PartnerTypeId"]);
                    if (!Convert.IsDBNull(dr["PartnerType"]))
                        objcmsPartnerTypeDO.PartnerType = Convert.ToString(dr["PartnerType"]);
                    if (!Convert.IsDBNull(dr["Description"]))
                        objcmsPartnerTypeDO.Description = Convert.ToString(dr["Description"]);
                    if (!Convert.IsDBNull(dr["Detail"]))
                        objcmsPartnerTypeDO.Detail = Convert.ToString(dr["Detail"]);
                    if (!Convert.IsDBNull(dr["CreatedDate"]))
                        objcmsPartnerTypeDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                    if (!Convert.IsDBNull(dr["OrderId"]))
                        objcmsPartnerTypeDO.OrderId = Convert.ToInt32(dr["OrderId"]);
                    if (!Convert.IsDBNull(dr["ParentID"]))
                        objcmsPartnerTypeDO.ParentID = Convert.ToInt32(dr["ParentID"]);
                    if (!Convert.IsDBNull(dr["Sale"]))
                        objcmsPartnerTypeDO.Sale = Convert.ToInt32(dr["Sale"]);
                    if (!Convert.IsDBNull(dr["SystemStatusId"]))
                        objcmsPartnerTypeDO.SystemStatusId = Convert.ToString(dr["SystemStatusId"]);
                    arrcmsPartnerTypeDO.Add(objcmsPartnerTypeDO);
                }
            }
            return arrcmsPartnerTypeDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPartnerType_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable SelectByCondition(int top, int parentId, int partnerTypeId)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsPartnerType_GetByCondition";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Top", SqlDbType.Int);
            Sqlparam.Value = top;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ParentId", SqlDbType.Int);
            Sqlparam.Value = parentId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PartnerTypeId", SqlDbType.Int);
            Sqlparam.Value = partnerTypeId;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        #endregion

    }

}
